#pragma once

#include "Atoi.h"
#include "Itoa.h"
#include "DBAccount.h"
#include "wch/StringTokenizer.h"
using namespace wch;
struct DBPlayer
{
	DBPlayer()
	: _account(nullptr) {}

	UInt64		_id;
	std::string	_nick;
	UInt8		_sex;
	std::string	_headIcon;
	UInt32		_rid;
	UInt32		_reportRid;
	std::vector<UInt32> _grpIds;
	UInt32		_loginTime;
	UInt32		_createdTime;

	DBAccount * _account;

	UInt64 getPromoter() { return _account->_promoter; }


	void addGameReport(UInt32 rid, UInt32 grid)
	{
		if (rid != _reportRid)
			_grpIds.clear();
		_reportRid = rid;
		_grpIds.push_back(grid);
	}

	void unBuildGameReports( const std::string& reports )
	{
		StringTokenizer tokenizer(reports, ":");
		if (tokenizer.count() < 2)
			return;
		_grpIds.clear();
		_reportRid = Atoi<UInt32>(tokenizer[0]);
		StringTokenizer idstr(tokenizer[1], "|");
		for (size_t i = 0; i < idstr.count(); ++i)
			_grpIds.push_back(Atoi<UInt32>(idstr[i]));
	}

	std::string buildGameReports()
	{
		if (_reportRid == 0 || _grpIds.empty())
			return "";
		std::string reports;
		reports.append(Itoa<UInt32>(_reportRid));
		reports.append(":");
		for (size_t i = 0; i < _grpIds.size(); ++i)
		{
			if (i > 0)
				reports.append("|");
			reports.append(Itoa<UInt32>(_grpIds[i]));
		}
		return reports;
	}
};